<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运动员的操作页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <script>
        $.ajaxSetup({
            async : false
        });
    </script>
</head>
<body>
<form class="layui-form" action="" id="Leader">
    <input type="hidden" name="athleteId" id="athleteIds"/>
    <div class="layui-form-item"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">运动员名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="athleteName" id="athleteNames" required
                   lay-verify="required" placeholder="运动员名称" autocomplete="off"/>
        </div>
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="deptName" id="deptNames" required
                   lay-verify="required" placeholder="部门名称" autocomplete="off"/>
        </div>
        <label class="layui-form-label">岗位名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="postName" id="postNames" required
                   lay-verify="required" placeholder="岗位名称" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">

        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <select name="athleteSex" id="athleteSexs" lay-filter="habit">
                <option value="男" selected="">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <label class="layui-form-label">注册单位</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="organName" id="organNames" required
                   lay-verify="required" placeholder="注册单位" autocomplete="off"/>
        </div>
        <label class="layui-form-label">籍贯</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="nativePlace" id="nativePlaces" required
                   lay-verify="required" placeholder="籍贯" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">

        <label class="layui-form-label">出生年月</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="birthday" id="birthdays" autocomplete="off" placeholder="请选择日期">
        </div>
        <label class="layui-form-label">进队时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="joinTime" id="joinTimes" autocomplete="off" placeholder="请选择日期">
        </div>
        <label class="layui-form-label">训练年限</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="trainingYears" id="trainingYearss" autocomplete="off" placeholder="请选择日期">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">习惯手</label>
        <div class="layui-input-inline">
            <select name="hand" id="hands" lay-filter="habit">
                <option value="左手" selected="">右手</option>
                <option value="右手">左手</option>
            </select>
        </div>
        <label class="layui-form-label">打法</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="play" id="plays" required
                   lay-verify="required" placeholder="打法" autocomplete="off"/>
        </div>
        <label class="layui-form-label">俱乐部</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="club" id="clubs" required
                   lay-verify="required" placeholder="俱乐部" autocomplete="off"/>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">技术等级</label>
        <div class="layui-input-inline">
            <select name="level" id="levels" lay-verify="required" lay-filter="skill">
                <option value="" selected=""></option>
            </select>
        </div>
        <label class="layui-form-label">教练员</label>
        <div class="layui-input-inline">
            <select name="coachName" id="coachNames" lay-verify="required" lay-filter="culture">
                <option value="" selected=""></option>
            </select>
        </div>
        <label class="layui-form-label">毕业学院</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="graduateSchool" id="graduateSchools" required
                   lay-verify="required" placeholder="毕业学院" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">


        <label class="layui-form-label">文化程度</label>
        <div class="layui-input-inline">
            <select name="education" id="educations" lay-verify="required" lay-filter="culture">
                <option value="" selected=""></option>
            </select>
        </div>
        <label class="layui-form-label">家庭情况</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="family" id="familys" required
                   lay-verify="required" placeholder="家庭状况" autocomplete="off"/>
        </div>
        <label class="layui-form-label">最好成绩</label>
        <div class="layui-input-inline">
            <select name="bestResult" id="bestResults" lay-verify="required" lay-filter="best">
                <option value="" selected=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">

        <label class="layui-form-label">运动员说明</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="athleteExp" id="athleteExps" required
                   lay-verify="required" placeholder="运动员说明" autocomplete="off"/>
        </div>
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="phone" id="phones" required
                   lay-verify="required" placeholder="职责说明" autocomplete="off"/>
        </div>
        <label class="layui-form-label">通讯地址</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="addr" id="addrs" required
                   lay-verify="required" placeholder="通讯地址" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">其他说明</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="other" id="others" required
                   lay-verify="required" placeholder="其他说明" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">

        <label class="layui-form-label">技术特征</label>
        <div class="layui-input-block">
            <textarea name="technical" id="technicals"  class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">战术特征</label>
        <div class="layui-input-block">
            <textarea name="tactics" id="tacticss"  class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">心理特征</label>
        <div class="layui-input-block">
            <textarea name="mentality" id="mentalitys"  class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
         <div class="layui-input-block">
             <button class="layui-btn site-demo-active" lay-submit lay-filter="formDemo" >立即提交</button>
             <button type="reset" class="layui-btn layui-btn-primary">重置</button>
         </div>
     </div>
</form>
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //日期渲染
        laydate.render({
            elem: '#birthdays'
            ,trigger:'click'
        });
        laydate.render({
            elem: '#trainingYearss'
            ,trigger:'click'
        });
        laydate.render({
            elem: '#joinTimes'
            ,trigger:'click'
        });
        /**
         * 新增和修改
         */
        var form = null ;
        layui.use('form', function(){
            form = layui.form;
            //监听提交
            form.on('submit(formDemo)', function(data){
                // 单击之后提交按钮不可选,防止重复提交
                var DISABLED = 'layui-btn-disabled';
                // 增加样式
                $('.site-demo-active').addClass(DISABLED);
                // 增加属性
                $('.site-demo-active').attr('disabled', 'disabled');
                var rolesId = "";
                $("input[name='athleteId']:checked").each(function(index,item){

                    rolesId+=$(this).val()+",";

                });
                data.field.athleteId=rolesId;

                var formData = new FormData(document.getElementById("Leader"));
                var url = "../../UserseControllerAthlete/insertUpdate";
                $.ajax({
                    url:url,
                    type:"post",
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        //alert("成功了");
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.tableTwo.reload();

                            //重新渲染
                            form.render();
                        });
                    },
                    error:function(e){
                        layer.msg("操作错误!");
                    }
                });
                return false;

            });

                //技术等级
                $.ajax({
                    type:"POST",
                    url:'../../UserseControllerAthlete/findBySkill',  //从数据库查询返回的是个list
                    dataType: "json",
                    contentType: false,
                    async: false,
                    cache: false,
                    success: function (data) {
                        $.each(data,function(index,item){
                            //$('#levels').append(new Option(item.dname));//往下拉菜单里添加元素
                            $('#levels' ). append("<option value='"+item.did+"'>"+item.dname+"</option>")
                        })
                        form.render("select");//菜单渲染 把内容加载进去
                    }
                })
                //文化程度
                $.ajax({
                    type:"POST",
                    url:'../../UserseControllerAthlete/findByCulture',  //从数据库查询返回的是个list
                    dataType: "json",
                    contentType: false,
                    async: false,
                    cache: false,
                    success: function (data) {
                        $.each(data,function(index,item){
                            //$('#educations').append(new Option(item.dname));//往下拉菜单里添加元素
                            $('#educations' ). append("<option value='"+item.did+"'>"+item.dname+"</option>")
                        })
                        form.render("select");//菜单渲染 把内容加载进去
                    }
                })
                //最好成绩
                $.ajax({
                    type:"POST",
                    url:'../../UserseControllerAthlete/findByBest',  //从数据库查询返回的是个list
                    dataType: "json",
                    contentType: false,
                    async: false,
                    cache: false,
                    success: function (data) {
                        $.each(data,function(index,item){
                            //$('#bestResults').append(new Option(item.dname));//往下拉菜单里添加元素
                            $('#bestResults' ). append("<option value='"+item.did+"'>"+item.dname+"</option>")
                        })
                        form.render("select");//菜单渲染 把内容加载进去
                    }
                })
                //现教练
                $.ajax({
                    type:"POST",
                    url:'../../UserseControllerAthlete/findByName',  //从数据库查询返回的是个list
                    dataType: "json",
                    contentType: false,
                    async: false,
                    cache: false,
                    success: function (data) {
                        $.each(data,function(index,item){
                            /*$('#coachNames').append(new Option(item.coachName, item.coachId));*///往下拉菜单里添加元素
                            //$('#coachNames').append(new Option(item.coachName));
                            $('#coachNames' ). append("<option value='"+item.coachId+"'>"+item.coachName+"</option>") ;

                        })
                        form.render("select");//菜单渲染 把内容加载进去
                    }
                })

                //体育项目
                $.ajax({
                    type:"POST",
                    url:'../../UserseControllerAthlete/findAllSportName',  //从数据库查询返回的是个list
                    dataType: "json",
                    contentType: false,
                    async: false,
                    cache: false,
                    success: function (data) {
                        $.each(data,function(index,item){
                            /*$('#sprotNames').append(new Option(item.sportName, item.sportId));*///往下拉菜单里添加元素
                            //$('#sportNames').append(new Option(item.sportName));
                            $('#sportNames' ). append("<option value='"+item.sportId+"'>"+item.sportName+"</option>")
                        })
                        form.render("select");//菜单渲染 把内容加载进去
                    }
                })
            var id = getQueryString("id");
            if(id !="" && id != null){
                    findlx(id);
            }
        });
        /**
         * 修改显示
         */
        function findlx(id){

            var url = "../../UserseControllerAthlete/selectMore";
            var data = {athleteId:id};
            //jquery的ajax方法,查询类型的方法
            $.post(url,data,function(obj){
                //从后台传过来的数据obj$("[value='11']").prop("checked",true);
                //alert("coachName"+obj.coachName);
                //alert("obj.sportName"+obj.sportName);
                $("#athleteIds").val(obj.athleteId);
                $("#athleteNames").val(obj.athleteName);
                $("#deptNames").val(obj.deptName);
                $("#postNames").val(obj.postName);
                $("#athleteSexs").val(obj.athleteSex);
                $("#organNames").val(obj.organName);
                $("#nativePlaces").val(obj.nativePlace);
                $("#birthdays").val(obj.birthday);
                $("#hands").val(obj.hand);
                $("#plays").val(obj.play);
                $("#clubs").val(obj.club);
                $("#trainingYearss").val(obj.trainingYears);
                $("#joinTimes").val(obj.joinTime);
                $("#levels").val(obj.level);
                //$("#oldCoachs").val(obj.oldCoach);
                $("#coachNames").val(obj.coachId);
                $("#graduateSchools").val(obj.graduateSchool);
                $("#educations").val(obj.education);
                $("#familys").val(obj.family);
                $("#bestResults").val(obj.bestResult);
                $("#athleteExps").val(obj.athleteExp);
                $("#phones").val(obj.phone);
                $("#addrs").val(obj.addr);
                $("#others").val(obj.other);
                $("#technicals").val(obj.technical);
                $("#tacticss").val(obj.tactics);
                $("#mentalitys").val(obj.mentality);
                $("#sportNames").val(obj.sportId);
                //console.info(obj.sportId);
                //重新渲染
                form.render("select");
            },"json");
        }
    });
</script>
</body>
</html>